package com.yinhai.activity;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.os.Bundle;
import android.util.DisplayMetrics;

import com.androidquery.AQuery;
import com.lz.util.Utils;

public class ChatViewImgActivity extends Activity {

	private AQuery aq = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.pop_chat_pic);
		aq = new AQuery(this);

		if (getIntent().hasExtra("pic")) {
			aq.id(R.id.chat_img).image(
					getIntent().getStringExtra("pic").toString(), true, true);
		} else if (getIntent().hasExtra("fileName")) {
			aq.id(R.id.chat_img).image(
					getIntent().getStringExtra("fileName").toString(),
					Utils.getImageOptions(ChatViewImgActivity.this,
							R.drawable.default_avatar_big, 0));
		}

	}

	// 缩放图片
	public Bitmap zoomImg(Bitmap bm) {
		// 获得图片的宽高
		int width = bm.getWidth();
		int height = bm.getHeight();

		DisplayMetrics dm = new DisplayMetrics();
		dm = this.getApplicationContext().getResources().getDisplayMetrics();

		int newWidth = dm.widthPixels;
		// 计算缩放比例
		float scaleWidth = ((float) newWidth) / width;
		// 取得想要缩放的matrix参数
		Matrix matrix = new Matrix();
		matrix.postScale(scaleWidth, scaleWidth);
		// 得到新的图片
		Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix,
				true);
		return newbm;
	}

}
